package top.eggcode.modules.user.model;

import lombok.Data;
import top.eggcode.common.lang.BeanUnit;

import java.time.LocalDateTime;
import java.util.LinkedList;
import java.util.List;

/**
 * Title:
 * Description: TODO
 * Date: 2021/5/16 8:53
 *
 * @author JiaQi Ding
 * @version 1.0
 */
@Data
public class RoleDTO {

    private String id;

    private String code;

    private String name;

    private String remark;

    private LocalDateTime createdAt;

    /**
     * id 列表
     */
    private List<String> powers;

    {
        this.setPowers(new LinkedList<>());
    }

    public static RoleDTO build(RoleEntity entity) {
        RoleDTO view = new RoleDTO();
        BeanUnit.copy(entity, view);
        return view;
    }

    public RoleEntity convert() {
        RoleBiz entity = new RoleBiz();
        BeanUnit.copy(this, entity);
        List<PowerEntity> powerList = new LinkedList<>();
        this.getPowers().stream().map(id -> {
            PowerEntity power = new PowerEntity();
            power.setId(id);
            return power;
        }).forEach(powerList::add);
        entity.setPowerList(powerList);
        return entity;
    }


}
